import requests
import logging


class APIClient:
    def __init__(self, besa_url):
        self.besa_url = besa_url
        self.session = requests.Session()
        self.session.headers.update({
            "Content-Type": "application/json",
            "Accept": "application/json",
            "User-Agent": "Mozilla/5.0",
        })
        logging.basicConfig(level=logging.INFO)

    def request(self, method, endpoint, **kwargs):
        url = self.besa_url + endpoint
        logging.info(f'Requesting {url}')
        response = self.session.request(method, url,**kwargs)
        logging.info(f'Response_code: {response.status_code}')
        logging.info(f'Response_text: {response.text}')
        return response

    def get(self, endpoint, **kwargs):
        return self.request('GET', endpoint, **kwargs)

    def post(self, endpoint, **kwargs):
        return self.request('POST', endpoint, **kwargs)

    def put(self, endpoint, **kwargs):
        return self.request('PUT', endpoint, **kwargs)